<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/1/21
 * Time: 20:37
 */

namespace app\api\controller;


use Bt\BtApi;

class Index extends  Common
{
    public function index(){
        $code = input("post.code" , 0 , "intval" );
        $data = input("post.data" );
        $arr = [];
        if($data){
            $data = json_decode($data , true);
        }else{
            $data = [];
        }
        $serverInfo = $this->SERVER_INFO;
        $bt = new BtApi($serverInfo["server"] , $serverInfo["key"] , $serverInfo["port"]);
        $res = $bt->get($code , $data);
        $arr = json_decode($res);
        if(!$arr && !is_numeric($res) ){     //检查是否有安装任务 返回结果不是一个标准的json
            return output(2002);
        }
        if(is_numeric($res)){
            return output(0,["count" => $res]);
        }
        return output(0 , $arr);
    }
}